package com.bootdo.wx.api;

import com.bootdo.common.utils.R;
import com.bootdo.common.utils.StringUtils;
import com.bootdo.wx.service.CmsContentService;
import com.bootdo.wx.service.MemberScoreService;
import com.bootdo.wx.service.MemberUserService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * Created by HP on 2019/7/25.
 */
@Controller
@RequestMapping("/api/score")
public class ApiScoreController {

    @Autowired
    private MemberScoreService memberScoreService;
    @Autowired
    private MemberUserService memberUserService;
    @Autowired
    private CmsContentService cmsContentService;


    /*
     * 查看个人积分记录
     * type 0：下级消费返利，1：签到，2分享，3自己消费返利5：消费,传空字符串是全部记录
     * */
    @ResponseBody
    @RequestMapping("/getMemberScoreList")
    public R getMemberScoreList(@RequestBody Map<String,Object> paramMap) {
        try{
            if (!paramMap.containsKey("userId") || StringUtils.isBlank(paramMap.get("userId").toString())
                    || !paramMap.containsKey("type") ) {
                return R.error("参数错误");
            }
            PageInfo<Map<String,Object>> list = memberScoreService.getMemberScoreList(paramMap);
            return R.ok().put("data", list);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("查询失败");
        }

    }
    
    
    /*
     * 获取积分任务奖励的积分
     * type 
     * */
    @ResponseBody
    @RequestMapping("/getTaskScore")
    public R getTaskScore() {
        try{
            return cmsContentService.getTaskScore();
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("查询失败");
        }

    }



}
